<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Tlist extends Controller
{
    
    protected function _initialize()
    {
        parent::_initialize();
    }
    public function index(){
        $s_date = date('Y-m-01 00:00:00', strtotime('-1 month'));
        $e_date = date('Y-m-01 00:00:00',time());
        // $e_date =  date('Y-m-t', strtotime('-1 month'));
        $where['a.add_time'] = ['between',[$s_date,$e_date]];
        // $list = db("jianlis")
        //     ->alias('a')
        //     ->join('jianlis b','a.tuijian=b.otuijian')
        //     ->where($where)
        //     ->field(['a.name,count(distinct b.openid) as count'])
        //     // ->where($where)
        //     ->group('a.name')
        //     ->order('count desc')
        //     ->limit(0,10)
        //     ->select();
        $list =  Db::query("SELECT b.count,a.name FROM `hs_jianlis` a inner join (SELECT `otuijian`,count(*) as count FROM `hs_jianlis` group by `otuijian`) b on a.tuijian=b.otuijian order by b.count desc limit 10");
        // $list = model('Jianlis')->order('update_time desc')->paginate(15);
        return $this->fetch('index',['list'=>$list,'e_date'=>$e_date]);   
    }
}